/**
 * 定义基础路由
 * @type { *[] }
 */

let moduleRoutes = [];
//以下方法是读取./modules/目录下的所有js文件
const routerContext = require.context("./modules/", true, /\.js$/);
routerContext.keys().forEach(filePath => {
  const routerModule = routerContext(filePath);
  // 兼容 import export 和 require module.export 两种规范 Es modules commonjs
  moduleRoutes = [...moduleRoutes, ...(routerModule.default || routerModule)];
});

const baseRoutes = [
  {
    path: "/",
    name: "Home",
    meta: { title: "首页", requireAuth: true },
    component: () =>
      import(/* webpackChunkName: "home" */ "@/views/home/Index.vue")
  },
  {
    path: "*",
    name: "notFound",
    meta: { title: "页面丢失了..." },
    component: () =>
      import(/* webpackChunkName: "notFound" */ "@/views/other/404")
  }
];

moduleRoutes = [...moduleRoutes, ...baseRoutes];

export const routes = moduleRoutes;
